home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume18 / diskhog2 < prev    next >
Encoding:
Internet Message Format  |  1989-03-26  |  21.7 KB

  1. Subject:  v18i067:  A diskquota-system for non-BSD sites
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: Dave Settle <mcvax!ucms!dave@uunet.UU.NET>
  7. Posting-number: Volume 18, Issue 67
  8. Archive-name: diskhog2
  9.  
  10. [  I had really mangled this last time I posted it.  Here's a good version.
  11.    Thanks to Mark Washburn for tracking this down and getting it to me.
  12.    --r$  ]
  13.  
  14.  
  15. 'diskhog' is a set of scripts to allow you to enforce disk quotas under
  16. system V.  You need to specify the blocks allowed for each.  user (as
  17. reported by 'du'), and run a check script every night.  Users who are
  18. listed in the 'allowed' file have disk quotas; those which are not listed
  19. have not.
  20.  
  21. You can also specify 'alternate' directories which are counted as well as
  22. the user's home directory.  (for example, I have "/usr/dave" and
  23. "~nuucp/dave").  All the files, irrespective of owner, are counted in
  24. these directories, which is perhaps a little unfair ...
  25.             Dave Settle, SMB Business Software, Thorn EMI Datasolve
  26.             [ Now Universal (CMS) Ltd.]
  27.  
  28. #! /bin/sh
  29. # This is a shell archive.  Remove anything before this line, then unpack
  30. # it by saving it into a file and typing "sh file".  To overwrite existing
  31. # files, type "sh file -c".  You can also feed this as standard input via
  32. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  33. # will see the following message at the end:
  34. #        "End of shell archive."
  35. # Contents:  Makefile README allowed alternate configure csh_hog.c
  36. #   dcheck dcheck.1 diskhog diskhog.1 diskhog.h nohog.1 nohog.c
  37. # Wrapped by rsalz@papaya.bbn.com on Mon Mar 27 12:53:44 1989
  38. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  39. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  40.   echo shar: Will not clobber existing file \"'Makefile'\"
  41. else
  42. echo shar: Extracting \"'Makefile'\" \(860 characters\)
  43. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  44. X#
  45. XBIN=/usr/local/bin                # directory for binaries
  46. XDQUOTAS=/usr/local/lib/disk
  47. X#
  48. XSRC1 = README Makefile configure allowed dcheck.1 alternate
  49. XSRC2 = dcheck diskhog diskhog.h nohog.c csh_hog.c nohog.1 diskhog.1 
  50. X
  51. Xconfig: .config
  52. X
  53. X.config:
  54. X    sh configure
  55. X    @touch .config
  56. X
  57. Xinstall: nohog dcheck diskhog allowed ${DQUOTAS}/hogs ${DQUOTAS}
  58. X    @echo "If your system has csh, maybe you need to 'make csh'"
  59. X    @echo "Try 'make -n csh' first."
  60. X    chown root nohog
  61. X    chmod 4111 nohog
  62. X    cp nohog ${BIN}
  63. X    chmod +x dcheck diskhog
  64. X    cp dcheck diskhog ${BIN} 
  65. X    cp allowed ${DQUOTAS}
  66. X
  67. Xcsh: csh_hog
  68. X    if [ ! -f /etc/csh ] ; then mv /bin/csh /etc/csh ; fi
  69. X    cp csh_hog /bin/csh
  70. X
  71. X${DQUOTAS}/hogs:
  72. X    mkdir ${DQUOTAS}/hogs
  73. X
  74. X${DQUOTAS}:
  75. X    mkdir ${DQUOTAS}
  76. X
  77. Xshar: ${SRC}
  78. X    shar -cv -p X ${SRC1} > diskhog.shar.1
  79. X    shar -cv -p X ${SRC2} > diskhog.shar.2
  80. X
  81. XREADME: README.nr
  82. X    nroff -cm README.nr > README
  83. END_OF_FILE
  84. if test 860 -ne `wc -c <'Makefile'`; then
  85.     echo shar: \"'Makefile'\" unpacked with wrong size!
  86. fi
  87. # end of 'Makefile'
  88. fi
  89. if test -f 'README' -a "${1}" != "-c" ; then 
  90.   echo shar: Will not clobber existing file \"'README'\"
  91. else
  92. echo shar: Extracting \"'README'\" \(4958 characters\)
  93. sed "s/^X//" >'README' <<'END_OF_FILE'
  94. X[  NOTE:  You  might have to edit "diskhog" to turn the printable control
  95. X   characters in the "stty" line into their real values. --r$  ]
  96. X
  97. XDISKHOG.
  98. X
  99. X1.  Introduction.
  100. X
  101. X          'diskhog' is a set of scripts to allow you to enforce disk quotas
  102. X       under system V.  You need to specify the blocks allowed for each. 
  103. X       user (as reported by 'du'), and run a check script every night.  Users
  104. X       who are listed in the 'allowed' file have disk quotas; those which are
  105. X       not listed have not.  
  106. X
  107. X           You can also specify 'alternate' directories which are counted 
  108. X       as well as the user's home directory.  (for example, I have 
  109. X       "/usr/dave" and "~nuucp/dave").  All the files, irrespective of 
  110. X       owner, are counted in these directories, which is perhaps a little 
  111. X       unfair ... 
  112. X
  113. X
  114. X2.  How it works. 
  115. X
  116. X            Basically, there is a file called "allowed", which  has
  117. X       a list of the number of disk blocks (as per "du") which each
  118. X       user is allowed.  The format of this file is
  119. X
  120. X               <user> <allowance>
  121. X
  122. X       where <user> is the user's login name,  and  <allowance>  is
  123. X       the maximum number of block they are allowed (as per "du").
  124. X
  125. X            There is also  an  optional  file  called  "alternate",
  126. X       containing   additional   directories  to  be  searched  for
  127. X       particular users. This is in the form:
  128. X
  129. X                        user    directory ....
  130. X                e.g.
  131. X                        dave    /usr/spool/uucppublic/dave /sys/dave
  132. X
  133. X            Each night, the script "dcheck" is run  from  the  root
  134. X       crontab entry, and checks each user's allowance. If the user
  135. X       has more than the allowance, a mail message is sent  to  the
  136. X       user asking them to remove some files.
  137. X
  138. X            If after a certain number of  days  the  user  has  not
  139. X       removed  enough  files, then a diskhog "tag" is created. The
  140. X       next time the user logs on, the shell notices this tag,  and
  141. X       spawns a restricted shell via the script "diskhog".
  142. X
  143. X            When running via "diskhog", the user's PATH is  set  to
  144. X       "/diskhog:/usr/diskhog",   so  that  you  can  restrict  the
  145. X       commands which are available. On my system, all the commands
  146. X       in   these   directories   relate  to  removing  files,  and
  147. X       formatting floppy disks to put them on.
  148. X
  149. X            When the user logs out of the restricted shell, another
  150. X       disk  check  is  performed,  and  if enough blocks have been
  151. X       removed, the login is allowed to proceed. If not,  "diskhog"
  152. X       is  run  again.  "Diskhog"  is  interrupt-proof,  but can be
  153. X       killed by a SIGHUP signal (i.e. turning off the terminal).
  154. X
  155. X            In order to prevent the user from removing the  diskhog
  156. X       "tag"  file,  the tag file is placed in a directory owned by
  157. X       root, which is not writeable by anyone else. The tag file is
  158. X       removed  by  a special command "nohog", which is executed by
  159. X       "diskhog" when enough files have been removed. "Nohog"  runs
  160. X       suid  root,  and is (hopefully) immune from fraud: it always
  161. X       removes the tag of the login user.
  162. X
  163. X            Obviously, you should not put "nohog" in the restricted
  164. X       PATH,  or the user would be able to remove their own diskhog
  165. X       tag!
  166. X
  167. X            All you need to run disk quotas is:
  168. X
  169. X         1.  An "allowed" file, containing disk allowances.
  170. X
  171. X         2.  If your system has "csh", then you need to type  "make
  172. X             csh", since csh does not have a system-wide init file.
  173. X             A small program is provided, which makes the  relevant
  174. X             check, and then calls the real csh.
  175. X
  176. X         3.  Add a line to the beginning of the file "/etc/profile"
  177. X             which reads:
  178. X
  179. X                     if [ -f $DQUOTAS/hogs/$LOGNAME ] ; then diskhog ; fi
  180. X
  181. X             where DQUTOAS is defined  as  your  disk  quota  admin
  182. X             directory (see Makefile).
  183. X
  184. X         4.  Make yourself an entry in the root crontab, which runs
  185. X             the program "dcheck" sometime during the night.
  186. X
  187. X                  This will read something like:
  188. X
  189. X             03      01      *       *       *       /usr/bin/dcheck
  190. X
  191. X             to run at 01:30 am every night.
  192. X
  193. X
  194. X       3.  Using csh with diskhog
  195. X
  196. X            Since   my   "csh"   doesn't   have    a    system-wide
  197. X       initialisation  file, it's difficult to intercept the logins
  198. X       of people using the c-shell.
  199. X
  200. X            I decided to intercept /bin/csh itself, so I moved  the
  201. X       real  csh  to  /etc/csh, and wrote a stub program which just
  202. X       checks for a tag file, and calls diskhog  if  it  finds  it.
  203. X       Then it calls the real csh.
  204. X
  205. X            This works fine on my system, but make  sure  it's  not
  206. X       going  to  interfere  with  things on your system before you
  207. X       install it.
  208. X
  209. X            Have fun.
  210. X
  211. X
  212. X            Dave Settle, SMB Business Software, Thorn EMI Datasolve
  213. X            [ Now Universal (CMS) Ltd.]
  214. END_OF_FILE
  215. if test 4958 -ne `wc -c <'README'`; then
  216.     echo shar: \"'README'\" unpacked with wrong size!
  217. fi
  218. # end of 'README'
  219. fi
  220. if test -f 'allowed' -a "${1}" != "-c" ; then 
  221.   echo shar: Will not clobber existing file \"'allowed'\"
  222. else
  223. echo shar: Extracting \"'allowed'\" \(67 characters\)
  224. sed "s/^X//" >'allowed' <<'END_OF_FILE'
  225. Xdave    100000        # Superman - God lives!
  226. Xallan    500        # Dimbo
  227. Xjane    10000
  228. END_OF_FILE
  229. if test 67 -ne `wc -c <'allowed'`; then
  230.     echo shar: \"'allowed'\" unpacked with wrong size!
  231. fi
  232. # end of 'allowed'
  233. fi
  234. if test -f 'alternate' -a "${1}" != "-c" ; then 
  235.   echo shar: Will not clobber existing file \"'alternate'\"
  236. else
  237. echo shar: Extracting \"'alternate'\" \(40 characters\)
  238. sed "s/^X//" >'alternate' <<'END_OF_FILE'
  239. Xdave    /usr/spool/uucppublic/dave    /tmp/ds
  240. END_OF_FILE
  241. if test 40 -ne `wc -c <'alternate'`; then
  242.     echo shar: \"'alternate'\" unpacked with wrong size!
  243. fi
  244. # end of 'alternate'
  245. fi
  246. if test -f 'configure' -a "${1}" != "-c" ; then 
  247.   echo shar: Will not clobber existing file \"'configure'\"
  248. else
  249. echo shar: Extracting \"'configure'\" \(1488 characters\)
  250. sed "s/^X//" >'configure' <<'END_OF_FILE'
  251. X
  252. X#
  253. X# shell script to install diskhog
  254. X#
  255. XDQUOTAS="/usr/lib/disk"
  256. XBIN="/usr/bin"
  257. X
  258. Xecho "Hi there, just a few questions about your system ..."
  259. Xcat << EOF
  260. XI need a place to hold all the information about disk usage and allowances.
  261. X
  262. XI would suggest using the directory $DQUOTAS.
  263. X
  264. XEOF
  265. Xecho "If you want a different one, enter it here: \c"
  266. Xread ANS
  267. Xif [ "$ANS" != "" ]
  268. Xthen
  269. X    DQUOTAS=$ANS
  270. X    echo "OK, using $DQUOTAS"
  271. Xfi
  272. Xif [ -f $DQUOTAS ]
  273. Xthen
  274. X    echo "Oh dear, that seems to be a file"
  275. X    echo "That won't do at all ..."
  276. X    exit 0
  277. Xelse
  278. X    if [ -d $DQUOTAS ]
  279. X    then
  280. X        echo "That directory already exists - I hope it's empty\n"
  281. X    else
  282. X        echo "Making a new directory"
  283. X        mkdir $DQUOTAS $DQUOTAS/hogs
  284. X        chmod 755 $DQUOTAS/hogs
  285. X        chown root $DQUOTAS/hogs
  286. X    fi
  287. Xfi
  288. Xcat << EOF
  289. XWhere do you intend to install the programs?
  290. X
  291. XI would suggest $BIN, but you might use another directory.
  292. X
  293. XEOF
  294. Xecho "If you want a different directory, enter it here: \c"
  295. Xread ANS
  296. Xif [ "$ANS" != "" ]
  297. Xthen
  298. X    BIN=$ANS
  299. X    echo "OK - using $BIN"
  300. Xfi
  301. Xecho "OK - reconfiguring the system ... \c"
  302. Xcat << EOF > diskhog.h
  303. X#define DQUOTAS "$DQUOTAS"
  304. X#define BIN "$BIN"
  305. XEOF
  306. Xed - dcheck << EOF > /dev/null
  307. X/^DQUOTAS=/c
  308. XDQUOTAS=$DQUOTAS            # directory containing all the info
  309. X.
  310. Xw
  311. Xq
  312. XEOF
  313. Xed - diskhog << EOF > /dev/null
  314. X/^DQUOTAS=/c
  315. XDQUOTAS=$DQUOTAS            # directory containing all the info
  316. X.
  317. Xw
  318. Xq
  319. XEOF
  320. Xed Makefile << EOF > /dev/null
  321. X/^BIN=/c
  322. XBIN=$BIN                # directory for binaries
  323. X.
  324. X/^DQUOTAS=/c
  325. XDQUOTAS=$DQUOTAS
  326. X.
  327. Xw
  328. Xq
  329. XEOF
  330. Xecho "OK - your system has been configured"
  331. END_OF_FILE
  332. if test 1488 -ne `wc -c <'configure'`; then
  333.     echo shar: \"'configure'\" unpacked with wrong size!
  334. fi
  335. chmod +x 'configure'
  336. # end of 'configure'
  337. fi
  338. if test -f 'csh_hog.c' -a "${1}" != "-c" ; then 
  339.   echo shar: Will not clobber existing file \"'csh_hog.c'\"
  340. else
  341. echo shar: Extracting \"'csh_hog.c'\" \(419 characters\)
  342. sed "s/^X//" >'csh_hog.c' <<'END_OF_FILE'
  343. X/*
  344. X * csh_hog.c: intercept "csh" and check for diskhog tags first
  345. X */
  346. X#include "diskhog.h"
  347. X#include <sys/types.h>
  348. X#include <sys/stat.h>
  349. Xchar *getenv();
  350. X
  351. Xmain(argc, argv)
  352. Xchar **argv;
  353. X{
  354. X    char *who = getenv(LOGNAME), cmd[64], fname[64];
  355. X    struct stat s;
  356. X    argv[argc] = 0;
  357. X    sprintf(fname, "%s/hogs/%s", DQUOTAS, who);
  358. X    sprintf(cmd, "%s/diskhog", BIN);
  359. X    if(stat(fname, &s) != -1) system(cmd);
  360. X    execv("/etc/csh", argv);
  361. X}
  362. X    
  363. END_OF_FILE
  364. if test 419 -ne `wc -c <'csh_hog.c'`; then
  365.     echo shar: \"'csh_hog.c'\" unpacked with wrong size!
  366. fi
  367. # end of 'csh_hog.c'
  368. fi
  369. if test -f 'dcheck' -a "${1}" != "-c" ; then 
  370.   echo shar: Will not clobber existing file \"'dcheck'\"
  371. else
  372. echo shar: Extracting \"'dcheck'\" \(3290 characters\)
  373. sed "s/^X//" >'dcheck' <<'END_OF_FILE'
  374. X
  375. X#
  376. X# check all users disk allocations, and mail disk hogs
  377. X#
  378. X# change IFS so that only <NL> is a separator - needed to pick up lines from
  379. X# /etc/passwd
  380. X#
  381. XIFS='
  382. X'
  383. XTEMP=/tmp/dcheck            # temp file for mail etc.
  384. XDQUOTAS=/usr/local/lib/disk            # directory containing all the info
  385. XUSAGE=$DQUOTAS/usage            # usages recorded here each night
  386. XMALIASES=/usr/lib/mailx/mailx.rc    # system mail aliases.
  387. XVIPS=100                # logins with uids less than this are not checked
  388. XLOG=$DQUOTAS/log            # log of warnings etc.
  389. XBOOK=$DQUOTAS/allowed            # where the index of allowances is kept
  390. XALTERNATE=$DQUOTAS/alternate        # list of other directories to add in
  391. XADMIN=root                # user informed of diskhogs
  392. XMAX=5                    # no of warnings issued before login restricted
  393. X#
  394. Xrm -f $USAGE
  395. XMC=`uname`
  396. Xfor u in `cat /etc/passwd`
  397. Xdo
  398. X#
  399. X# scan /etc/passwd file for users.
  400. X# get USER (name) UID, and HDIR (home directory).
  401. X#
  402. X    USER=`echo $u | awk 'BEGIN{FS=":"} {print $1}'`
  403. X    UID=`echo $u | awk 'BEGIN{FS=":"} {print $3}'`
  404. X    HDIR=`echo $u | awk 'BEGIN{FS=":"} {print $6}'`
  405. X    if [ -f "$ALTERNATE" ]
  406. X    then
  407. X        OTHERS=`grep "$USER" "$ALTERNATE" | sed 's/[a-zA-Z]* //'`
  408. X    else
  409. X        OTHERS=""
  410. X    fi
  411. X#
  412. X# check MALIASES for "alias $USER real_user"
  413. X#
  414. X    MALIAS=`grep "alias $USER " /usr/lib/mailx/mailx.rc | awk '{print $3}'`
  415. X    if [ "$MALIAS" = "" ]
  416. X    then
  417. X        MALIAS=$USER
  418. X    fi
  419. X#
  420. X# ignore users with uids less than $VIPS
  421. X#
  422. X    if [ $UID -lt "$VIPS" ]
  423. X    then
  424. X        continue
  425. X    fi
  426. X    ALLOWED=`grep "^$USER[     ]" $BOOK | awk '{print $2}'`
  427. X    if [ "$ALLOWED" = "" ]
  428. X    then
  429. X        continue        # no definition of disk usage
  430. X    fi
  431. X    DISK=`du -s $HDIR $OTHERS | awk '{total += $1} END{print total}'`
  432. X#
  433. X# keep record of current disk use
  434. X#
  435. X    echo "$USER has $DISK, allowed $ALLOWED" >> $USAGE
  436. X#
  437. X# send warning if disk usage is over 90% of allowed
  438. X#
  439. X    THRESHOLD=`expr "$ALLOWED" - \( "$ALLOWED" / 10 \)`
  440. X    if [ "$DISK" -gt "$THRESHOLD" ] && [ "$DISK" -lt "$ALLOWED" ]
  441. X    then
  442. X        /bin/mail $MALIAS << EOF
  443. XSubject:  disk usage warning
  444. X
  445. XYour disk usage ($ALLOWED) is nearly used up
  446. XYou have $DISK blocks
  447. XEOF
  448. X    fi
  449. X    if [ "$DISK" -gt "$ALLOWED" ]
  450. X    then
  451. X        TIME=`date`
  452. X#
  453. X# if no count file present, then create one.
  454. X#
  455. X        if [ ! -f $DQUOTAS/$USER ]
  456. X        then
  457. X            cat "1" > $DQUOTAS/$USER
  458. X        fi
  459. X        COUNT=`cat $DQUOTAS/$USER`
  460. X        EXCESS=`expr "$DISK" - "$ALLOWED"`
  461. X        /bin/mail $MALIAS << EOF
  462. XSubject:  Disk usage
  463. X
  464. XYour disk usage on $MC is $DISK blocks.
  465. XYou are allowed only $ALLOWED blocks -- please remove $EXCESS blocks.
  466. XEOF
  467. X        echo "$USER allowed $ALLOWED has $DISK - warned $TIME" >> $LOG
  468. X        COUNT=`expr "$COUNT" + 1`
  469. X        echo $COUNT > $DQUOTAS/$USER
  470. X        if [ "$COUNT" -gt "$MAX" ]
  471. X        then
  472. X#
  473. X# warned too many times -
  474. X# mail supervisor, and give restricted logins until files removed.
  475. X# 
  476. X            /bin/mail $ADMIN << EOF
  477. XSubject:  Disk hog $USER
  478. X
  479. X$USER has ignored all my warnings about disk quotas. I have therefore
  480. Xrestricted ${USER}'s login.
  481. X$USER has $EXCESS too many blocks on $MC, with a quota of $ALLOWED blocks.
  482. XEOF
  483. X            echo "Disk hog $USER restricted on $TIME" >> $LOG
  484. X#
  485. X# create tag file, to be found by the login shell
  486. X#
  487. X            touch $DQUOTAS/hogs/$USER
  488. X#
  489. X# make sure the files can't be accessed by anyone else - peter logs in as
  490. X# other people! You can remove the check for peter, if you want it to work
  491. X# for everyone.
  492. X#
  493. X#            if [ "$USER" = "peter" ]
  494. X#            then
  495. X                chmod go-rx $HDIR
  496. X#            fi
  497. X        fi
  498. X    else
  499. X        echo "1" > $DQUOTAS/$USER
  500. X    fi
  501. Xdone
  502. X
  503. X
  504. END_OF_FILE
  505. if test 3290 -ne `wc -c <'dcheck'`; then
  506.     echo shar: \"'dcheck'\" unpacked with wrong size!
  507. fi
  508. chmod +x 'dcheck'
  509. # end of 'dcheck'
  510. fi
  511. if test -f 'dcheck.1' -a "${1}" != "-c" ; then 
  512.   echo shar: Will not clobber existing file \"'dcheck.1'\"
  513. else
  514. echo shar: Extracting \"'dcheck.1'\" \(460 characters\)
  515. sed "s/^X//" >'dcheck.1' <<'END_OF_FILE'
  516. X.TH DCHECK 1M
  517. X.SH SYNOPSIS
  518. Xdcheck    -    send mail to potential disk hogs
  519. X.SH DESCRIPTION
  520. X.P
  521. X\fBdcheck\fR is normally run from the \fBcrons\fR procedure to check
  522. Xif users are taking up too much space.
  523. XIt creates a \fBtag\fP file for such users, will send them warning
  524. Xmail, and also sends mail to the system administrator about what it's
  525. Xdone.
  526. X.SH SEE ALSO
  527. X.P
  528. Xdiskhog(1).
  529. X.SH FILES
  530. X.P
  531. X$DQUOTAS/hogs/$LOGNAME        - tag file indicating that \fBdiskhog\fR 
  532. Xshould be run
  533. END_OF_FILE
  534. if test 460 -ne `wc -c <'dcheck.1'`; then
  535.     echo shar: \"'dcheck.1'\" unpacked with wrong size!
  536. fi
  537. # end of 'dcheck.1'
  538. fi
  539. if test -f 'diskhog' -a "${1}" != "-c" ; then 
  540.   echo shar: Will not clobber existing file \"'diskhog'\"
  541. else
  542. echo shar: Extracting \"'diskhog'\" \(1472 characters\)
  543. sed "s/^X//" >'diskhog' <<'END_OF_FILE'
  544. X#
  545. X# script that naughty people get when they don't remove files
  546. X#
  547. Xtrap '' 2 3
  548. Xstty erase ^H kill ^U echoe intr ^? quit ^\
  549. XSHELL=/bin/sh
  550. Xexport SHELL PATH
  551. X#
  552. X# re-check the disk allocation
  553. X#
  554. XDQUOTAS=/usr/local/lib/disk            # directory containing all the info
  555. XHOG=1
  556. Xecho "\nOvernight check shows you have too much disk space"
  557. Xwhile [ "$HOG" = "1" ]
  558. Xdo
  559. X    PATH=/bin:/usr/bin:/usr/ucb
  560. X    echo "Re-checking your disk usage .... \c"
  561. X    ALLOWED=`grep $LOGNAME $DQUOTAS/allowed | awk '{print $2}'`
  562. X    DISK=`du -s . | awk '{print $1}'`
  563. X    echo "done"
  564. X    if [ "$DISK" -gt "$ALLOWED" ]
  565. X    then
  566. X        echo "You have $DISK blocks, but are allowed only $ALLOWED"
  567. X        echo "You must remove some files before you can logon"
  568. X        echo "You now have a restricted shell with the following commands"
  569. X        ls -C /diskhog /usr/diskhog
  570. X        echo "Remove some files and then type CONTROL-D"
  571. X
  572. X#
  573. X# if we allow interrupts in this shell, we get zapped on return
  574. X# so - fork a shell, and allow interrupts there
  575. X# we have to give a command to trap, so that spawned commands get SIG_DFL,
  576. X# or we can't reset them when we get there!
  577. X# You may have to say "trap 3" to unlock the QUIT signal.
  578. X#
  579. X        trap 'echo "** interrupt ignored **"' 2 3
  580. X        /bin/sh << EOF
  581. XPATH=/diskhog:/usr/diskhog
  582. XSHELL=/bin/rsh
  583. Xexport PATH SHELL
  584. Xexec /bin/rsh < /dev/tty        # signals get set to SIG_DFL
  585. XEOF
  586. X        trap '' 2 3        # ignore SIGINT SIGQUIT
  587. X    else
  588. X        echo "I see that you have removed your excess disk blocks - thankyou"
  589. X        nohog
  590. X        HOG=0
  591. X        chmod og+rx $HOME
  592. X    fi
  593. Xdone
  594. END_OF_FILE
  595. echo shar: 1 control character may be missing from \"'diskhog'\"
  596. if test 1472 -ne `wc -c <'diskhog'`; then
  597.     echo shar: \"'diskhog'\" unpacked with wrong size!
  598. fi
  599. chmod +x 'diskhog'
  600. # end of 'diskhog'
  601. fi
  602. if test -f 'diskhog.1' -a "${1}" != "-c" ; then 
  603.   echo shar: Will not clobber existing file \"'diskhog.1'\"
  604. else
  605. echo shar: Extracting \"'diskhog.1'\" \(922 characters\)
  606. sed "s/^X//" >'diskhog.1' <<'END_OF_FILE'
  607. X.TH DISKHOG 1
  608. X.SH SYNOPSIS
  609. Xdiskhog - run a restricted shell to persuade a user to remove some files.
  610. X.SH DESCRIPTION
  611. X.P
  612. X\fBdiskhog\fR is a shell script initiated for a user who has failed to 
  613. Xremove excess disk blocks.
  614. X.P
  615. XIt rechecks the current disk usage, and if this is still greater than the
  616. Xmaximum allowed, runs a restricted shell (\fB/bin/rsh\fR), with a \fBPATH\fR
  617. Xset to \fB/diskhog:/usr/diskhog\fR.
  618. X.P
  619. XWhen this shell terminates, a further check is made of the disk usage, and
  620. Xif it is now acceptable, the normal login process will continue. Otherwise
  621. Xthe process will be repeated.
  622. X.P
  623. XThe \fBdiskhog\fR procedure is interrupt-proof, and can only be exited by
  624. Xeither removing sufficient blocks, or on receipt of a SIGHUP signal
  625. X(e.g. turning the terminal off).
  626. X.SH SEE ALSO
  627. X.P
  628. Xdcheck(1M), du(1), sh(1), csh(1), nohog(1)
  629. X.SH FILES
  630. X.P
  631. X$DQUOTAS/hogs/$LOGNAME        - tag file indicating that \fBdiskhog\fR 
  632. Xshould be run
  633. END_OF_FILE
  634. if test 922 -ne `wc -c <'diskhog.1'`; then
  635.     echo shar: \"'diskhog.1'\" unpacked with wrong size!
  636. fi
  637. # end of 'diskhog.1'
  638. fi
  639. if test -f 'diskhog.h' -a "${1}" != "-c" ; then 
  640.   echo shar: Will not clobber existing file \"'diskhog.h'\"
  641. else
  642. echo shar: Extracting \"'diskhog.h'\" \(67 characters\)
  643. sed "s/^X//" >'diskhog.h' <<'END_OF_FILE'
  644. X#define DQUOTAS "/usr/local/lib/disk"
  645. X#define BIN "/usr/local/bin"
  646. END_OF_FILE
  647. if test 67 -ne `wc -c <'diskhog.h'`; then
  648.     echo shar: \"'diskhog.h'\" unpacked with wrong size!
  649. fi
  650. # end of 'diskhog.h'
  651. fi
  652. if test -f 'nohog.1' -a "${1}" != "-c" ; then 
  653.   echo shar: Will not clobber existing file \"'nohog.1'\"
  654. else
  655. echo shar: Extracting \"'nohog.1'\" \(429 characters\)
  656. sed "s/^X//" >'nohog.1' <<'END_OF_FILE'
  657. X.TH NOHOG 1M
  658. X.SH SYNOPSIS
  659. Xnohog    -    remove the diskhog tag file for the invoking user.
  660. X.SH DESCRIPTION
  661. X.P
  662. X\fBnohog\fR is normally run from the \fBdiskhog\fR procedure, when the user
  663. Xhas removed sufficient disk blocks.
  664. X.P
  665. XIt removes the \fBtag\fR file created by \fBdcheck\fR.
  666. X.SH SEE ALSO
  667. X.P
  668. Xdcheck(1M), diskhog(1), du(1), sh(1), csh(1),
  669. X.SH FILES
  670. X.P
  671. X$DQUOTAS/hogs/$LOGNAME        - tag file indicating that \fBdiskhog\fR 
  672. Xshould be run
  673. END_OF_FILE
  674. if test 429 -ne `wc -c <'nohog.1'`; then
  675.     echo shar: \"'nohog.1'\" unpacked with wrong size!
  676. fi
  677. # end of 'nohog.1'
  678. fi
  679. if test -f 'nohog.c' -a "${1}" != "-c" ; then 
  680.   echo shar: Will not clobber existing file \"'nohog.c'\"
  681. else
  682. echo shar: Extracting \"'nohog.c'\" \(860 characters\)
  683. sed "s/^X//" >'nohog.c' <<'END_OF_FILE'
  684. X/*
  685. X * nohog.c: remove diskhog tag from /etc/hogs directory
  686. X *
  687. X * find out who the user is, and then remove the tag from the hogs directory.
  688. X *
  689. X * It's supposed to be proof against fraud, though I wouldn't care to put
  690. X * any money on it.
  691. X *
  692. X * runs suid root, so that the user can't just 'rm' the file.
  693. X *
  694. X * This program should NOT be accessible to diskhogs running the "diskhog"
  695. X * shell - i.e. don't link it to /diskhog or /usr/diskhog
  696. X */
  697. X#include <sys/types.h> 
  698. X#include <utmp.h>
  699. X#include <stdio.h>
  700. X
  701. X#include "diskhog.h"
  702. Xchar *ttyname(); 
  703. Xstruct utmp *getutline();
  704. X
  705. Xmain(){
  706. X    char *p;
  707. X    struct utmp *utmp, mine;
  708. X    int prefix = sizeof "/dev/";
  709. X    chdir(DQUOTAS);
  710. X    chdir("hogs");
  711. X    p = ttyname(fileno(stderr));        /* find tty device */
  712. X    strcpy(mine.ut_line, p + 5);
  713. X    if(utmp = getutline(&mine))
  714. X        unlink(utmp->ut_user);
  715. X    else printf("who are you?\n");
  716. X    return(0);
  717. X}
  718. END_OF_FILE
  719. if test 860 -ne `wc -c <'nohog.c'`; then
  720.     echo shar: \"'nohog.c'\" unpacked with wrong size!
  721. fi
  722. # end of 'nohog.c'
  723. fi
  724. echo shar: End of shell archive.
  725. exit 0
  726.